/* $$Id: RssItemView.java 30 2008-01-09 15:16:48Z qxodream $$
 *
 * RssReaderMidlet --  RSS reader for J2ME(midp)
 * The original codes of this porgram is from
 * RssOwlMIDlet(zhengyun@gmail.com)
 *
 * Copyright (c) 2007-2008 QXO(qxodream@gmail.com)
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the Free
 * Software Foundation; either version 2 of the License, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

package com.ultrapower.view;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Item;
import javax.microedition.lcdui.StringItem;

import com.ultrapower.control.GUIController;
import com.ultrapower.model.RssItem;
import com.ultrapower.tools.ResUtils;

/**
 * 类说明：“查看新闻摘要”的Form界面 查看选定的Rss Item的详细信息,包括新闻链接以及摘要。仅提供一个“返回”按钮。
 *
 * @author zhengyun@ultrapower 2005.10.07
 * @author QXO(qxodream@gmail.com)
 *
 */
public class RssItemView extends Form {
	private GUIController controller;
	private Command BACK_COMMAND;
	private StringItem titleField;
	private StringItem urlField;
	private StringItem descriptionField;

	public RssItemView(String title, GUIController control) {
		super(title);
		controller = control;
		this.setCommandListener(new RssFeedViewListener());

		BACK_COMMAND = new Command(ResUtils.getLabel(ResUtils.CMD_BACK), Command.BACK, 1);
		this.addCommand(BACK_COMMAND);

		titleField = new StringItem(ResUtils.getItemLabel(ResUtils.RSS_TITLE_KEY), title);

		urlField = new StringItem(ResUtils.getItemLabel(ResUtils.RSS_LINK_KEY), "",Item.HYPERLINK);
		descriptionField = new StringItem(ResUtils.getItemLabel(ResUtils.RSS_CONTENT_KEY), "");
		this.append(titleField);
		this.append(descriptionField);
		this.append(urlField);
	}

	public void setRssItem(RssItem item) {
		titleField.setText(item.getTitle());
		urlField.setText(item.getLink());
		descriptionField.setText(item.getDescription());
	}

	/*
	 * 内部监听器，监听器监听所有Command事件，并把事件响应推出来让控制器处理
	 */
	private class RssFeedViewListener implements CommandListener {
		public void commandAction(Command command, Displayable disp) {
			if (command == BACK_COMMAND) {
				controller.handleEvent(
						GUIController.EventID.EVENT_VIEW_RSS_ITEM_BACK, null);
			}
		}
	}// end inner class
}
